package wikipedia;


import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

import javax.net.ssl.HttpsURLConnection;

/**
 * this class get wiki content of a movie(not finished)
 *
 * @author chenji
 *
 */
public class GetWikiContent {
	public static void main(String[] args) throws Exception {
		new GetWikiContent().sendGet("movie");
	}

	// HTTP GET request
	private void sendGet(String qry) throws Exception {

		String url = "http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Film&prop=revisions&rvprop=content";
  	URL obj = new URL(url);
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();

		// optional default is GET
		con.setRequestMethod("GET");

		// add request header
		con.setRequestProperty("User-Agent", "Mozilla/5.0");

		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'GET' request to URL : " + url);
		System.out.println("Response Code : " + responseCode);

		BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
		String inputLine;
		StringBuffer content = new StringBuffer();

		while ((inputLine = in.readLine()) != null) {
			content.append(inputLine);
		}
		in.close();
		
		System.out.println(content);
		
		// TODO Process the xml content
	}
}